package cn.anc.aonicardv.net;

import android.net.Network;
import android.os.Build;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.net.SocketFactory;

/**
 * Created by yangdai on 2018/2/25.
 */

public class NetworkSocketFactory extends SocketFactory {

    private Network mNetwork;

    public NetworkSocketFactory(Network network) {
        mNetwork = network;
    }

    @Override
    public Socket createSocket() throws IOException {
        Socket socket = new Socket();
        try {
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && mNetwork != null) {
                mNetwork.bindSocket(socket);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return socket;
    }

    @Override
    public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
        return null;
    }

    @Override
    public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
        return null;
    }

    @Override
    public Socket createSocket(InetAddress host, int port) throws IOException {
        return null;
    }

    @Override
    public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
        return null;
    }
}
